import { instance } from "../axios";

// 获取社区帖子列表
export const getCommunityPosts = () => {
  return instance.get('/api/forums/all');
};

// 获取单个帖子详情
export const getPostById = (postId) => {
  return instance.get(`/api/community/posts/${postId}`);
};

// 发布新帖子
export const createPost = (data) => {
  return instance.post('/api/forums/create', data);
};

// 搜索帖子
export const searchPosts = (query, filter = 'all') => {
  return instance.get('/api/community/search', { params: { query, filter } });
};

// 获取热门标签
export const getHotTags = () => {
  return instance.get('/api/community/tags/hot');
};

// 获取社区公告
export const getCommunityAnnouncements = () => {
  return instance.get('/usercenter/notices');
};

// 获取社区精华帖子
export const getFeaturedPosts = () => {
  return instance.get('/api/community/posts/featured');
};

// 点赞帖子
export const likePost = (postId) => {
  return instance.post(`/api/community/posts/${postId}/like`);
};

// 取消点赞
export const unlikePost = (postId) => {
  return instance.delete(`/api/community/posts/${postId}/like`);
};

// 获取帖子评论
export const getPostComments = (postId) => {
  return instance.get(`/api/community/posts/${postId}/comments`);
};

// 发表评论
export const createComment = (postId, content) => {
  return instance.post(`/api/community/posts/${postId}/comments`, { content });
};

// 获取用户的帖子
export const getUserPosts = (userId) => {
  return instance.get('/api/community/user/${userId}/posts', { userId });
};

// 管理员发布公告
export const publishNotice = (adminId, topic, content) => {
  return instance.post('/admin/notice', null, { 
    params: { adminId, topic, content } 
  });
};

// 管理员获取所有公告
export const getAdminNotices = () => {
  return instance.get('/admin/notice');
};

// 管理员删除公告
export const deleteNotice = (noticeId) => {
  return instance.delete(`/admin/notice/${noticeId}`);
};
